package com.iteaj.network.test;

import com.iteaj.network.config.ConnectProperties;
import com.iteaj.network.test.client.line.LineClientComponent;
import com.iteaj.network.test.server.line.TestLineBasedFrameDecoderComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

@EnableConfigurationProperties(IotTestProperties.class)
public class IotTestAutoConfiguration {

    @Autowired
    private IotTestProperties properties;

    @Bean
    @ConditionalOnExpression("${iot.test.server}")
    public TestLineBasedFrameDecoderComponent lineBasedFrameDecoderComponent() {
        return new TestLineBasedFrameDecoderComponent(properties.getLine());
    }

    @Bean
    public LineClientComponent lineClientComponent() {
        return new LineClientComponent(new ConnectProperties(properties.getHost(), 15800));
    }
}
